<?php


namespace Admin\Model;
use Think\Model;
class UsersModel extends Model {
   
       
    protected $up_id = '';
    
    
    /**
     * 后置操作方法
     * 自定义的一个函数 用于数据保存后做的相应处理操作, 使用时手动调用
     * @param int $goods_id 商品id
     */
    /*获取上级id 根据级别*/
 public function get_up_id($user_id,$level=3)
{  
    $user = M('users')->field('user_id,is_activate,level,first_leader')->where(array('user_id' => $user_id))->find();
    if ($user['first_leader']>0) {

     $tjr = M('users')->field('user_id,is_activate,level,first_leader')->where(array('user_id' => $user['first_leader']))->find();

    if ($tjr['level']>=$level) {
        $this->up_id=$tjr['user_id'];
        return $this->up_id;
    }else{
       $this->get_up_id($user['first_leader'],$level);
       return $this->up_id;
    }
    
    }

    
}
    
}
